package com.wang.config;

import com.alipay.easysdk.factory.Factory;

import com.alipay.easysdk.kernel.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @Classname AlipayConfig
 * @Description 初始化支付宝的相关配置
 * @Date 2024/10/18 13:51
 * @Created by pc
 */
@Component
public class AlipayConfig implements ApplicationRunner {

    @Value("${alipay.appId}")
    private String appId;
    @Value("${alipay.privateKey}")
    private String privateKey;
    @Value("${alipay.publicKey}")
    private String publicKey;
    @Value("${alipay.gateway}")
    private String gateway;

    @Value("${alipay.notifyUrl}")
    private String notifyUrl;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Factory.setOptions(getOptions());
        System.out.println("************支付宝SDK初始化完成********");
    }

    public Config getOptions(){
        Config config = new Config();
        config.protocol="https"; // 协议
        config.gatewayHost=this.gateway;// 网关
        config.signType="RSA2";// 加密算法类型
        config.appId=this.appId;
        config.merchantPrivateKey = this.privateKey;// 私钥
        config.alipayPublicKey = this.publicKey;// 支付宝公钥
        config.notifyUrl = this.notifyUrl; // 支付宝回调接口
        return config;
    }
}
